package com.gitee.huxing.course.conc.conc02.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.conc02.lock
 * @ClassName: Count
 * @Author: huxingmale
 * @DateTime: 2021-08-24 21:25
 */
public class Count {
    final ReentrantLock lock = new ReentrantLock();

    public void get(){
        try {
            lock.lock();
            System.out.println(Thread.currentThread().getName() + "get begin");
            Thread.sleep(1000L);
            System.out.println(Thread.currentThread().getName() + "get end");
            lock.unlock();
        }catch (InterruptedException ex){
            ex.printStackTrace();
        }
    }

    public void put(){
        try {
            lock.lock();
            System.out.println(Thread.currentThread().getName() + "put begin");
            Thread.sleep(1000L);
            System.out.println(Thread.currentThread().getName() + "put end");
            lock.unlock();
        }catch (InterruptedException ex){
            ex.printStackTrace();
        }
    }
}
